<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>

<body class="hold-transition login-page">
    <form id='but' action="appDetail.php" method="post">
        <div class="am-u-sm-12 am-u-md-6 ">
            <div class="am-input-group am-input-group-sm">
                <input type="text" id='aname' name="aname" placeholder="手机号" value="" class="am-form-field">
                <button class="am-btn">ewewewe</button>
            </div>
        </div>
    </form>
</body>
<script>
    window.onload = function (e) {
        var code = "";
        var lastTime, nextTime;
        var lastCode, nextCode;

        document.onkeypress = function (e) {
            nextCode = e.which;
            nextTime = new Date().getTime();

            if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
                code += String.fromCharCode(lastCode);
            } else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
                code = "";
            }

            lastCode = nextCode;
            lastTime = nextTime;
        }

        this.onkeypress = function (e) {
            console.log(e.which);

            if (e.which == 13) {
                // $('#aname').val(code); //自动填充到表单
                // $('#but').submit();  //自动提交指定的表单
                // console.log(code);
                code = "";
            }
        }
    }

</script>

</html>